//
//  BenefitCell.swift
//  SitPosition
//
//  Created by apple on 2019/1/13.
//  Copyright © 2019 apple. All rights reserved.
//

import Foundation
import UIKit
import Cartography


/**
 * 用户收益列表Cell
 */
class BenefitCell : UITableViewCell, Reuseable {
    
    private lazy var roundedBackgroundView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        view.layer.cornerRadius = 5
        return view
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.black
        label.font = Theme.Font.regularFont(ofSize: 14)
        label.textAlignment = .left
        label.numberOfLines = 0
        label.lineBreakMode = .byTruncatingTail
        return label
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        backgroundColor = UIColor.clear
        contentView.backgroundColor = UIColor.clear
        selectionStyle = .none
        
        contentView.addSubview(roundedBackgroundView)
        roundedBackgroundView.addSubview(titleLabel)
        _setupContraints()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 标题
    public var title: String? = nil {
        didSet {
            titleLabel.text = title
        }
    }
}

// MARK: - Private Methods

extension BenefitCell {
    
    // 设置视图约束
    func _setupContraints() {
        // roundedBackgroundView
        constrain(roundedBackgroundView, contentView) { v, parent in
            v.edges == inset(parent.edges, 5, 15, 5, 15)
        }
        
        // titleLabel
        constrain(titleLabel, roundedBackgroundView) { v, parent in
            v.edges == inset(parent.edges, 12, 12, 12, 12)
        }
    }
}
